Component({
  properties: {
    // a-tubiaoai_huaban2fuben5 | pingjia | fenleitab | icon_chose | a-tubiaoai_huaban7fuben15 | a-tubiaoai_huaban7fuben16 | a-xuanzhongsvg_huaban2fuben12 | a-tubiaoai_huaban2fuben11 | a-tubiaoai_huaban2fuben31 | a-9-9_huaban2fuben10 | a-tubiaoai_huaban2fuben9 | a-2 | a-4 | a-tubiaoai_huaban2fuben7 | a-tubiaoai_huaban2fuben4 | a-tubiaoai_huaban2fuben3 | icon_shopping_off2 | icon_shopping_on1 | icon_chakan | icon_dingdan | icon_sure | icon_news | icon_trumpet1 | icon_into | icon_car | icon_start | a-icon_minus_huaban7fuben8 | icon_labe | a-icon_next_huaban7fuben5 | icon_add1 | icon_classify_off | icon_classify_on | icon_home_off | icon_home_on | icon_me_on | icon_shopping_off | icon_me_off | icon_shopping_on | icon_shopping | icon_add
    name: {
      type: String,
    },
    // string | string[]
    color: {
      type: null,
      observer: function (color) {
        this.setData({
          colors: this.fixColor(),
          isStr: typeof color === 'string',
        });
      },
    },
    size: {
      type: Number,
      value: 18,
      observer: function (size) {
        this.setData({
          svgSize: (size / 750) * wx.getSystemInfoSync().windowWidth,
        });
      },
    },
  },
  data: {
    colors: '',
    svgSize: (18 / 750) * wx.getSystemInfoSync().windowWidth,
    quot: '"',
    isStr: true,
  },
  methods: {
    fixColor: function () {
      var color = this.data.color;
      var hex2rgb = this.hex2rgb;

      if (typeof color === 'string') {
        return color.indexOf('#') === 0 ? hex2rgb(color) : color;
      }

      return color.map(function (item) {
        return item.indexOf('#') === 0 ? hex2rgb(item) : item;
      });
    },
    hex2rgb: function (hex) {
      var rgb = [];

      hex = hex.substr(1);

      if (hex.length === 3) {
        hex = hex.replace(/(.)/g, '$1$1');
      }

      hex.replace(/../g, function (color) {
        rgb.push(parseInt(color, 0x10));
        return color;
      });

      return 'rgb(' + rgb.join(',') + ')';
    },
  },
});
